package project2;

import evolution_superclasses.Genetic_Operators;
import evolution_superclasses.Genotype;

public class spiking_neuron_Genetic_Operators extends Genetic_Operators {
	private double _valueMutationRate = -1;

	public spiking_neuron_Genetic_Operators(int size) {
		super(size);
	}

	public double get_valueMutationRate() {
		return _valueMutationRate;
	}

	public void set_valueMutationRate(double bitMutationRate) {
		_valueMutationRate = bitMutationRate;
	}

	@Override
	public void crossOver(Genotype gen1, Genotype gen2) {
		int crossOverPoint = _rand.nextInt(_genSize);
		spiking_neuron_genotype bg1 = (spiking_neuron_genotype)gen1;
		spiking_neuron_genotype bg2 = (spiking_neuron_genotype)gen2;

		int[] array1 = bg1.get_params();
		int[] array2 = bg2.get_params();

		int i, tmp;
		for(i = 0; i < crossOverPoint; i++){
			bg1.edit_params(i, array1[i]);
			bg2.edit_params(i, array2[i]);
		}
		for(;i < _genSize; i++){
			tmp = array1[i];
			bg1.edit_params(i, array2[i]);
			bg2.edit_params(i, tmp);
		}
	}

	@Override
	public void mutation(Genotype gen1) {
		if(_valueMutationRate < 0)_valueMutationRate = 0.05;
		for(int i = 0; i < gen1.get_genSize(); i++){
			if(_valueMutationRate > _rand.nextDouble())
				((spiking_neuron_genotype)gen1).createRandomForPosistion(i);
		}

	}

}
